<!DOCTYPE html>
<html>
<head lang="zh">
    <meta charset="UTF-8">
    <title>商品详情</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/css/fruitdetails/mystyle.css"/>
    <link rel="stylesheet" href="/css/fruitdetails/shopsingle.css"/>
    <script src="/js/jquery-3.4.1.js"></script>
    <script src="/js/bootstrap.min.js"></script>
</head>
<body>
<div class="header-title">
    <div class="container">
        <div class="title-content">
            <h2>
                <strong class="clr-txt">naturix </strong>
                <span class="light-font">水果铺子</span>
            </h2>
            <p><a href="#">首页</a><span> / 商店</span></p>
        </div>
    </div>
</div>

<div class="container outboard" style="overflow: hidden;line-height: 200%">
    <!--左侧展示-->
    <!--background-color: red;-->
    <div class="col-lg-3" style="">
        <!--background-color: #f0ad4e-->
        <div style="">
            <div class="li-title">
                <h3>按<strong>类别</strong>细化</h3>
            </div>
            <div class="dropdown">

                <ul class="u1 font16">
                    <li>
                        <img src="/img/fruitdetails/箭头.png" alt=""/>
                        <span>水果</span>
                        <ul class="u2 font16">
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">苹&nbsp;&nbsp;果</a>
                            </li>
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">樱&nbsp;&nbsp;桃</a>
                            </li>
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">菠&nbsp;&nbsp;萝</a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <img src="/img/fruitdetails/箭头.png" alt=""/>
                        <span>水果拼盘</span>
                        <ul class="u2 font16">
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">苹&nbsp;&nbsp;果</a>
                            </li>
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">樱&nbsp;&nbsp;桃</a>
                            </li>
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">菠&nbsp;&nbsp;萝</a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <img src="/img/fruitdetails/箭头.png" alt=""/>
                        <span>折扣水果</span>
                        <ul class="u2 font16">
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">苹&nbsp;&nbsp;果</a>
                            </li>
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">樱&nbsp;&nbsp;桃</a>
                            </li>
                            <li>
                                <img src="/img/fruitdetails/箭头.png" alt=""/>
                                <a href="#">菠&nbsp;&nbsp;萝</a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>

        <div class="divider-full-1"></div>

        <!--background-color: #f0ad4e-->
        <div style="">
            <div class="li-title">
                <h3>Natrix<strong>亮点</strong></h3>
            </div>
            <div class="dropdown font16">
                <ul class="u1"  style="">
                    <li><input type="checkbox" id="trait"> 当天交易</li>
                    <li><input type="checkbox"> 新鲜运输</li>
                    <li><input type="checkbox"> 最畅销</li>
                    <li><input type="checkbox"> 特色产品</li>
                </ul>
            </div>
        </div>

        <!--background-color: #f0ad4e-->
        <div style="">
            <div class="li-title">
                <h3>按<strong>价格范围</strong>排序</h3>
            </div>
            <div class="dropdown font16">
                价格：￥10——￥100
            </div>
        </div>

        <!--background-color: #f0ad4e-->
        <div class="font16" style="">
            <div class="li-title">
                <h3>畅销<strong>水果</strong></h3>
            </div>

            <div class="box-outer1">
                <div class="box-img1">
                    <img src="/img/fruitdetails/post-xs-1.png" alt="黑莓"/>
                </div>

                <div class="box-content1">
                    <p>有机<strong>黑莓</strong></p>
                    <span></span>
                    <p ><strong>￥15.00</strong><del>￥25</del></p>
                </div>
            </div>

            <div class="box-outer1">
                <div class="box-img1">
                    <img src="/img/fruitdetails/post-xs-2.png" alt="桃"/>
                </div>

                <div class="box-content1">
                    <p>有机<strong>桃</strong></p>
                    <span></span>
                    <p><strong>￥18.00</strong><del>￥30</del></p>
                </div>
            </div>

            <div class="box-outer1">
                <div class="box-img1">
                    <img src="/img/fruitdetails/post-xs-3.png" alt="红梅"/>
                </div>

                <div class="box-content1">
                    <p>有机<strong>红梅</strong></p>
                    <span></span>
                    <p ><strong>￥15.00</strong><del>￥30</del></p>
                </div>
            </div>

            <div class="box-outer1">
                <div class="box-img1">
                    <img src="/img/fruitdetails/post-xs-4.png" alt="葡萄"/>
                </div>

                <div class="box-content1">
                    <p>有机<strong>葡萄</strong></p>
                    <span></span>
                    <p><strong>￥15.00</strong><del>￥30</del></p>
                </div>
            </div>
        </div>

        <!--background-color: #f0ad4e-->
        <div style="">
            <div class="li-title">
                <h3>按<strong>标签</strong>查找</h3>
            </div>
            <div style="margin-top: 15px">
                <div class="tag1"><button>水果</button></div>
                <div class="tag1"><button>蔬菜</button></div>
                <div class="tag1"><button>果汁</button></div>
                <div class="tag1" style="width: 33%;"><button style="padding: 3px 12px">天然食品</button></div>
                <div class="tag1"><button>餐饮</button></div>
                <div class="tag1"><button>面包</button></div>
                <div class="tag1"><button>自然</button></div>
                <div class="tag1"><button>健康</button></div>

            </div>
        </div>
    </div>

    <!--右侧展示-->
    <!--background-color: yellow;-->
    <div class="col-lg-9 right-show" style="">
        <!--background-color: orangered;border-right: 2px solid yellow;-->
        <div class="col-lg-6 right-pic" style="">
            <div>
                <a href="">
                    <!--./img/fruitdetails/prod-single-thumb-1.png-->
                    <img src="" id="show-pic" alt="" style="width:100%;"/>
                </a>
            </div>
            <div style="position:relative">
                <!--background-color: orange;-->
                <div class="smpic-div" style="">
                    <!--background-color: orange;-->
                    <div id="fruit-pic">
                        <!--/img/fruitdetails/thumb-1.png-->
                        <div class="small-pic"><a href=""><img src="" alt=""/></a></div>
                        <div class="small-pic"><a href=""><img src="" alt=""/></a></div>
                        <div class="small-pic"><a href=""><img src="" alt=""/></a></div>
                        <div class="small-pic"><a href=""><img src="" alt=""/></a></div>
                    </div>
                </div>
                <div class="pre-pic">
                    <button class="btn" style="outline: 0;color: #e7e7e6;"><</button>
                </div>
                <div class="next-pic">
                    <button class="btn" style="outline: 0;color: #e7e7e6;">></button>
                </div>
            </div>
        </div>

        <!--background-color: orangered;-->
        <div class="col-lg-6 detail-div">
            <div class="detail-title">
                <img src="/img/fruitdetails/title1.png" alt="" style="margin-right: 3px;width: 52px"/>
                <img src="/img/fruitdetails/title2.png" alt="" style="margin-right: 80px;width: 52px"/>
                <img src="/img/fruitdetails/评星1.png" class="star" alt=""/>
                <img src="/img/fruitdetails/评星1.png" class="star" alt=""/>
                <img src="/img/fruitdetails/评星1.png" class="star" alt=""/>
                <img src="/img/fruitdetails/评星1.png" class="star" alt=""/>
                <img src="/img/fruitdetails/评星1.png" class="star" alt=""/>
                <span>来自25份评论</span>
            </div>

            <div class="box-content1 detail-content" style="float: none">
                <p class="fruit-name">有机<strong id="fruit-name" style="margin-left: 5px"></strong></p>
                <span></span>
                <p class="fruit-price">
                    <!--<strong>￥18.00</strong>-->
                    <!--<del>￥30</del>-->
                </p>
                <p class="fruit-describe"></p>
            </div>

            <div class="detail-select">
                <div class="fruit-amount">
                    <div class="amount-minus">
                        <button>
                            <img src="/img/fruitdetails/minus.png" alt=""/>
                        </button>
                    </div>
                    <div class="amount-value">
                        <input title="数量" value="1">
                    </div>
                    <div class="amount-plus">
                        <button>
                            <img src="/img/fruitdetails/plus.png" alt=""/>
                        </button>
                    </div>

                </div>

                <!-- Small button group -->
                <div class="btn-group fruit-unit">
                    <select class="form-control">
                        <option>斤</option>
                        <option>公斤</option>
                        <option>个</option>
                    </select>
                </div>

                <div class="stock-confirm">
                    <img src="/img/fruitdetails/true.png" alt=""/>
                    <span>现货供应</span>
                </div>
            </div>

            <div class="fruit-content">
                <p><strong>S&nbsp;K&nbsp;U&nbsp;：</strong>AB2922-B<span id="fruit-id"></span></p>

                <p><strong>类&nbsp;&nbsp;别&nbsp;：</strong>水果&nbsp;&nbsp;<span id="fruit-category"></span></p>

                <p><strong>活&nbsp;&nbsp;动&nbsp;：</strong><span id="fruit-activity"></span></p>
            </div>


            <div class="submmit-cart">
                <button class="btn" style="color: white;outline: 0"><strong>添加到购物车</strong></button>
            </div>

        </div>

        <div class="col-lg-12 font20" style="height: 50px;margin-top: 5px;line-height: 50px;text-align: center;border-bottom: 1px dashed;box-sizing: border-box">
            <span style="margin-right: 50px">项目<strong>说明</strong></span>
            <span style="margin-right: 50px">附加<strong>信息</strong></span>
            <span>商品<strong>评论(<span id="comment-amount"></span>)</strong></span>
        </div>

        <div class="col-lg-12" style="padding: 0;position: relative">
            <div class="font16" style="margin-top: 10px;margin-bottom: 20px;width: 80%;text-align: center;display: inline-block;margin-left:10%">
                顾客评论(<span id="currpage-comment-amount"></span>)
            </div>
            <div id="comments" style="width: 80%;margin-left:10%">




            </div>
        </div>

    </div>
</div>

<script src="/js/fruitdetails/details.js"></script>
<script>
    var url = location.href;
    var fruitId = url.split("/")[url.split("/").length-1];
    var fruitName;

    $.getJSON("/fruitdetail/"+fruitId,function (data) {
        console.log(data);
        $('#show-pic').attr("src",data.fruitPics[0].picUrl);
        $('#fruit-pic img').eq(0).attr("src",data.fruitPics[0].picUrl);
        $('#fruit-pic img').eq(1).attr("src",data.fruitPics[1].picUrl);
        $('#fruit-pic img').eq(2).attr("src",data.fruitPics[2].picUrl);
        $('#fruit-pic img').eq(3).attr("src",data.fruitPics[3].picUrl);
        $('#fruit-name').html(data.fruitName);
        fruitName = data.fruitName;

        $('.fruit-describe').html(data.fruitDescript);
        if (null != data.detailActivityFruits){

            $('.fruit-price').html("<strong>￥"+data.detailActivityFruits[0].fruitActivityCost+"</strong><del>"+data.fruitPrice+"</del>")
        }else{
            $('.fruit-price').html("<strong>￥"+data.fruitPrice);
        }

        $('#fruit-id').html(data.fruitId);
        for ( var i=0; i<data.detailFruitCategories.length; i++){
            $('#fruit-category').append(data.detailFruitCategories[i].categoryInfo.categoryName+"&nbsp;&nbsp;");
        }
        for ( var i=0; i<data.detailActivityFruits.length; i++){
            $('#fruit-activity').append(data.detailActivityFruits[i].activityInfo.activityName+"&nbsp;&nbsp;");
        }

    })


    //加入购物车
    $('.submmit-cart>button').on("click",function () {
        var fruitId = $('#fruit-id').html();
        var fruitAmount = $('.amount-value>input').val();
        $.post("/shoppingcart/insertcart?fruitId="+fruitId+"&fruitAmount="+fruitAmount,function (data) {
            console.log(data)
        })
    });

    //获取userid
    var userId;

    $.get("/comment/getuserid",function (data) {
        userId = data;
    });


    // 评论
    var commentResult;
    var current_page;
    function get_comment(obj) {
        var resourceId = url.split("/")[url.split("/").length-1];
        $.getJSON("/comment/showcomment?currentPage="+obj+"&resourceId="+resourceId,function (data) {
            console.log(data);
            commentResult = data;
            current_page = obj;

            var html = "";

            //总评论数
            $('#comment-amount').html(data.totalSize);

            //当前页评论数
            $('#currpage-comment-amount').html(data.dataList.length);

            //水果无评价
            if (data.dataList == null){
                html += '<div><span>暂无评论</span></div>';
                $('#comments').html(html);
                return;
            }
            for (var i=0; i<data.dataList.length; i++){
                html += '<div class="comment-outer"><div class="comment-customer"><div class="customer-review">';
                html += '<img src="/img/fruitdetails/review.png" alt=""/></div><div class="customer-info">';
                html += '<span class="customer-name">'+data.dataList[i].senderName+'</span><br/>';
                html += '<span class="create-time">'+data.dataList[i].commentTime+'</span>';
                html += '<span class="info-spilt"> | </span><span class="resource-name">'+fruitName+'</span></div>';
                html += '<div class="comment-star">';

                for ( var j=0; j<data.dataList[i].commentStar; j++){
                    html += '<img src="/img/fruitdetails/评星1.png" alt=""/>';
                }
                html += '<span>评星：<span>'+data.dataList[i].commentStar+'</span>/5</span></div></div><div class="comment-content">';
                html += '<span class="content-txt">'+data.dataList[i].commentContent+'</span><div style="margin-top: 15px">';

                var urls = data.dataList[i].commentPic;
                if (urls != null){
                    for (var j=0; j<urls.length; j++){
                        html += '<img src="'+data.dataList[i].commentPic[j]+'" style="margin-right: 15px;width: 150px;border: 2px dashed #eee">'
                    }
                }


                html += '</div></div>';
                html += '<div><div class="comment-handle"><span class="hidden">'+data.dataList[i].id+'</span><a href="" data-toggle="modal" data-target=".bs-example-modal-lg" onclick="open_moudel(this)">';
                html += '<img src="/img/fruitdetails/comment.png" class="comment-pic" alt=""/><span>评论</span>';
                html += '<span style="font-size: 5px;font-weight: 800">';

//                if (data.dataList[i].commentResponses !== null){
//                    html +=data.dataList[i].commentResponses.length;
//                }

                html += '</span></a><a href="javascript:void(0);" onclick="thumb_up(this)">';
                var liked = false;
                if (data.dataList[i].thumbUpAmount !== 0){
                    for ( var j=0; j<data.dataList[i].thumbUpAmount; j++){

                        $.get("/comment/getuserid",function (data) {
                            userId = data;
                        });

                        if (data.dataList[i].thumbUperId[j] == userId){
                            html += '<img src="/img/fruitdetails/liked.png" class="comment-like-pic" alt=""/>';
                            liked = true;
                            break;
                        }
                    }
                }

                if (!liked){
                    html += '<img src="/img/fruitdetails/like.png" class="comment-like-pic" alt=""/>';
                }

                html += '<span>点赞</span><span>'+data.dataList[i].thumbUpAmount+'</span></a><a href="">';
                html += '<img src="/img/fruitdetails/more.png" class="comment-more-pic" alt=""/></a></div></div></div>'

            }

            //分页
            var pages = Math.ceil(commentResult.totalSize/commentResult.pageSize);
            html += '<nav aria-label="Page navigation" style="text-align: center">';
            html += '<ul class="pagination"><li><a href="javascript:void(0);" aria-label="Previous" onclick="pre_page(this)"><span aria-hidden="true">&laquo;</span></a></li>';
            for (var i=0; i<pages; i++){

                if ( current_page == i+1){
                    html += '<li class="active"><a href="javascript:void(0);" onclick="to_page(this)">'+(i+1)+'</a></li>';
                }else{
                    html += '<li><a href="javascript:void(0);" onclick="to_page(this)">'+(i+1)+'</a></li>';
                }

            }
            html += '<li><a href="javascript:void(0);" aria-label="Next" onclick="next_page(this)"><span aria-hidden="true">&raquo;</span></a></li></ul></nav>';

            //模态框
            html += '<div class="modal fade bs-example-modal-lg" id="my-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">';
            html += '<div class="modal-dialog modal-lg" role="document"><div class="modal-content">';
            html += '<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
            html += '<h4 class="modal-title" id="myModalLabel">评价详情</h4></div><div class="modal-body">';
            html += '</div></div></div></div>';

            $('#comments').html(html);
//            page(current_page);
        })
    }
    get_comment(1);


    //一级评论名
    var firstUserName;
    //二级三级评论直接获取
    function get_allresponse() {
        $.post("/comment/showallresponse?id="+commentId,function (data) {
            console.log(data);


            var html ='';
            if (data == null || data == "") {
                $('#is-comment').html("暂无评论");
            } else {
                for (var i = 0; i < data.length; i++) {
                    if (data[i] == null){
                        continue;
                    }

                    html += '<div class="comment-second" style="padding-left: 20px"><div class="user-info"><div class="user-review">';
                    html += '<img src="/img/fruitdetails/review.png" alt=""/></div><div class="user-infos"><span class="user-name">';
                    html += data[i].senderName + '</span><br/><span class="user-ctime">';
                    html += data[i].commentTime;
                    html += '</span></div></div>';
                    html += '<div style="float: right;margin-top: -50px;padding-right: 25px"><span style="display: none">'+data[i].id+'</span><a href="#response" onclick="reply(this)">回复</a></div>';
                    html += '<div class="comment-content"><span class="content-txt">';
                    html += data[i].responseContent + '</span></div></div>';


                    if (data[i].responses == null){
                        continue;
                    }

                    for (var m=0; m<data[i].responses.length; m++){
                            html += '<div class="comment-third"><div class="user-info"><div class="user-review">';
                            html += '<img src="/img/fruitdetails/review.png" alt=""/></div><div class="user-infos"><span class="user-name">';
                            html += data[i].responses[m].senderName+'</span><br/><span class="user-ctime">';
                            html += data[i].responses[m].commentTime;
                            html += '</span></div></div>';
                            html += '<div style="float: right;margin-top: -50px;padding-right: 16px"><span style="display: none">'+data[i].responses[m].id+'</span><a href="#response" onclick="newreply(this)">回复</a></div>';
                            html += '<div class="comment-content">';
                            html += '<span class="touser">回复'+data[i].responses[m].receiverName;
                            html += ':</span><span class="content-txt">';
                            html += data[i].responses[m].responseContent+'</span></div></div>';
                        }

                    firstUserName = data[0].receiverName;
                }

            }
            //被回复的姓名
            $('#replied-name').html(firstUserName);
            $('#all-comment').html(html);
        })
    }

    //将信息写在模态框
    var commentId;
    function open_moudel(obj) {
        var html = '<div class="comment-customer">'+$(obj).parent().parent().parent().children().eq(0).html()+'</div><div class="comment-content">'+$(obj).parent().parent().parent().children().eq(1).html()+'</div>';
        html += '<div class="cr"><img src="/img/fruitdetails/comment.png" alt=""/><span id="is-comment">全部评论</span><span id="return-response" style="float: right;padding-right: 25px;"></span></div>';
        html += '<div id="all-comment"></div>';
        commentId =  $(obj).parent().children().eq(0).html();

        //评论框
        html += '<div id="response"><div class="row"><div class="col-lg-1" style="font-weight: 900;color:#7fba00">@<span id="replied-name">回复</span>：</div><div class="col-lg-11"><div class="input-group">';
        html += '<input type="text" id="reply-content" class="form-control" placeholder="请输入评论内容" autocomplete="off">';
        html += '<span class="input-group-btn"><button class="btn btn-default" style="background-color: #7fba00;color: white" type="button" onclick="add_response(this)">';
        html += '提交</button></span></div></div></div></div></div>';

        $('.modal-body').html(html);

        get_allresponse();

    }

    //评论框切换到评论二级评论状态
    //二级评论id
    var responseId;
    function reply(obj){
        responseId = $(obj).parent().children().eq(0).html();

        //回复名
        var receiverName = $(obj).parent().parent().children().eq(0).children().eq(1).children().eq(0).html();



        var html = '';
        html += '<div id="response" class="row"><div class="col-lg-1" style="font-weight: 900;color:#acacac">@<span id="replied-name">'+receiverName+'</span>：</div><div class="col-lg-11"><div class="input-group">';
        html += '<input type="text" id="reply-content" class="form-control" placeholder="请输入您的回复内容" autocomplete="off">';
        html += '<span class="input-group-btn"><button class="btn btn-default" style="background-color: #acacac;color: white" type="button" onclick="add_reply(this)">';
        html += '提交</button></span></div></div></div></div>';

        $('#response').html(html);
        $('#return-response').html('<a href="#response" style="color: #7fba00" onclick="response()">发起评论</a>');

        //获得焦点
        document.getElementById("reply-content").focus();
        //window.scrollTo(0, document.documentElement.scrollHeight-document.documentElement.clientHeight);
    }

    //评论框切换到评论三级级评论状态
    //三级评论id
    var replyId;
    function newreply(obj){
        replyId = $(obj).parent().children().eq(0).html();

        //回复名
        var receiverName = $(obj).parent().parent().children().eq(0).children().eq(1).children().eq(0).html();


        var html = '';
        html += '<div id="response" class="row"><div class="col-lg-1" style="font-weight: 900;color:#acacac">@<span id="replied-name">'+receiverName+'</span>：</div><div class="col-lg-11"><div class="input-group">';
        html += '<input type="text" id="reply-content" class="form-control" placeholder="请输入您的回复内容" autocomplete="off">';
        html += '<span class="input-group-btn"><button class="btn btn-default" style="background-color: #c9e2b3;color: white" type="button" onclick="add_new_reply(this)">';
        html += '提交</button></span></div></div></div></div>';

        $('#response').html(html);
        $('#return-response').html('<a href="#response" style="color: #7fba00" onclick="response()">发起评论</a>');

        //获得焦点
        document.getElementById("reply-content").focus();
    }

    //评论框切换到评论一级评论状态
    function response() {
        var html = '';
        html += '<div id="response" class="row"><div class="col-lg-1" style="font-weight: 900;color:#7fba00">@<span id="replied-name">'+firstUserName+'</span>：</div><div class="col-lg-11"><div class="input-group">';
        html += '<input type="text" id="reply-content" class="form-control" placeholder="请输入评论内容" autocomplete="off">';
        html += '<span class="input-group-btn"><button class="btn btn-default" style="background-color: #7fba00;color: white" type="button" onclick="add_response(this)">';
        html += '提交</button></span></div></div></div></div>';

        $('#response').html(html);
        $('#return-response').html('');
        //获得焦点
        document.getElementById("reply-content").focus();
    }

    //添加二级评论的三级评论
    function add_reply(obj) {

        var content = $(obj).parent().parent().children().eq(0).val();

        if ( content === null || content === ''){
            alert("评论内容不能为空");
            return;
        }
        $('#my-modal').modal('toggle');
        $.post("/comment/addreply?id="+responseId+"&content="+content, function (data) {

            if (data == "success"){

                alert("添加成功");
                $('#myModal').modal('toggle');
                get_comment(current_page);

//                $.post("/comment/getmessagealert?id="+commentId,function (result) {
//                    console.log(result)
//                })
            }else if (data === "fail"){
                alert("添加失败");
            }

        })
    }

    //添加三级评论的三级评论
    function add_new_reply(obj) {

        var content = $(obj).parent().parent().children().eq(0).val();

        if ( content === null || content === ''){
            alert("评论内容不能为空");
            return;
        }
        $('#my-modal').modal('toggle');
        $.post("/comment/addnewreply?id="+replyId+"&content="+content, function (data) {

            if (data == "success"){

                alert("添加成功");
                $('#myModal').modal('toggle');
                get_comment(current_page);

//                $.post("/comment/getmessagealert?id="+commentId,function (result) {
//                    console.log(result)
//                })
            }else if (data === "fail"){
                alert("添加失败");
            }

        })
    }


    //提交二级评论

    var commentId;
    function add_response(obj) {

        var addresponseContent = $(obj).parent().parent().children().eq(0).val();
        if (addresponseContent === null || addresponseContent ===''){
            alert("评论内容不能为空");
            return;
        }
        $('#my-modal').modal('toggle');
        $.post("/comment/addresponse?id="+commentId+"&content="+addresponseContent,function (data) {

            if (data == "success"){

                alert("添加成功");
                $('#myModal').modal('toggle');
                get_comment(current_page);

//                $.post("/comment/getmessagealert?id="+commentId,function (result) {
//                    console.log(result)
//                })

            }else if (data === "fail"){
                alert("添加失败");
            }
        })
    }



    //点赞取消赞功能
    function thumb_up(obj) {

        if ($(obj).children().eq(0).attr("src") === "/img/fruitdetails/liked.png"){
            $(obj).children().eq(0).attr("src","/img/fruitdetails/like.png");
            $.post("/comment/thumbup?id="+$(obj).parent().children().eq(0).html());
            $(obj).children().eq(2).html(parseInt($(obj).children().eq(2).html())-1);
            return;
        }else{
            $(obj).children().eq(0).attr("src","/img/fruitdetails/liked.png");
            $.post("/comment/thumbup?id="+$(obj).parent().children().eq(0).html());
            $(obj).children().eq(2).html(parseInt($(obj).children().eq(2).html())+1);
            return;
        }
    }


    //分页功能
    function to_page(obj) {
        get_comment($(obj).html());
    }

    function pre_page(obj) {
        current_page = current_page-1;

        if (current_page == 0){
            current_page = 1;
        }
        get_comment(current_page);
    }

    function next_page(obj) {
        current_page = current_page+1;

        if (current_page > Math.ceil(commentResult.totalSize/commentResult.pageSize)){
            current_page = Math.ceil(commentResult.totalSize/commentResult.pageSize);
        }
        get_comment(current_page);
    }
</script>


</body>
</html>